package com.example.renyang.happysell;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.example.renyang.happysell.MyUntil.Car;
import com.example.renyang.happysell.net.HttpUtil;

import org.json.JSONArray;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import infClass.Food;


public class fragment_orderMan extends Fragment {
    private List<Map<String,Object>> mData;
    private ListView listView;
    private List<Food> list;
    private Context context;
    private TextView fdname;
    private TextView fdprice;
    private Button okbt;
    final JSONArray[] obj = {new JSONArray()};
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
        View view= inflater.inflate(R.layout.fragment_order_man, container, false);
        Intent intent=new Intent();
        Bundle bundle=new Bundle();

        fdname=(TextView)view.findViewById(R.id.order_food_name);
        fdprice=(TextView)view.findViewById(R.id.order_price);
        fdname.setText(fragment_shopcart.food.getFname());
        Log.i("zx", fragment_shopcart.food.getFname()+"johnjohn");
        fdprice.setText(fragment_shopcart.food.getPrice());
        okbt=(Button)view.findViewById(R.id.order_btok);
        okbt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               submit(fdname.getText().toString(),fdprice.getText().toString());
            }
        });

        return view;
    }

    private void submit(String name,String fdprice) {
        try {
            String url = HttpUtil.BASE_URL + "sendOrderInform?name="+name+"&price="+fdprice;
            String s = HttpUtil.getRequest(url);
            obj[0] =new JSONArray(s);
            JSONArray array = obj[0];
            if(array!=null){
                Log.i("zx","send ok ok");
            }
        }catch (Exception e){
            e.printStackTrace();
            Log.i("zx","send succ");
        }

    }
   /* public void showInfo(final int position){
        new AlertDialog.Builder(this).setTitle("")
    }*/



    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        context=activity;
    }


}
